//
//  UserInfoController.m
//  BShop
//
//  Created by chenguibang on 2017/8/10.
//  Copyright © 2017年 chenguibang. All rights reserved.
//

#import "UserInfoController.h"
#import <GBSexPickView.h>
#import <GBDatePickerView.h>
#import "GBTextEditController.h"
#import <PortraitPicker.h>
#import <Photos/PHFetchOptions.h>
#import <Photos/Photos.h>
#import <SDImageCache.h>
#import <AliyunOSSiOS/OSSService.h>
#import "GBOSSUtil.h"
@interface UserInfoController (){
    NSArray *menus;
}

@end

@implementation UserInfoController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setupView{
    self.title = @"个人信息";
    
    
    //    self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    //    [self.view addSubview:self.tableView];
    //    self.tableView.delegate = self;
    //    self.tableView.dataSource = self;
    //     [_tableView setContentOffset:CGPointMake(CGFLOAT_MAX, CGFLOAT_MAX)];
    
    
    
    
    
    
    
    menus = @[
              @[
                  @{
                      @"title":@"头像",
                      @"content":@"修改头像",
                      @"img":@"cancle"
                      },
                  ],
              
              @[
                  
                  @{
                      @"title":@"昵称",
                      @"content":@"老铁没毛病",
                      @"img":@""
                      },
                  @{
                      @"title":@"性别",
                      @"content":@"男",
                      @"img":@""
                      
                      },
                  @{
                      @"title":@"生日",
                      @"content":@"1992.9.29",
                      @"img":@""
                      }
                  ],
              
              @[
                  @{
                      @"title":@"地址管理",
                      @"content":@"管理地址",
                      @"img":@""
                      
                      },
                  ],
              ];
    
}


#pragma mark - UITableView_DataSource


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return menus.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [menus[section] count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        cell.textLabel.font = [UIFont systemFontOfSize:14];
        cell.detailTextLabel.font = [UIFont systemFontOfSize:14];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    cell.textLabel.text = menus[indexPath.section][indexPath.row][@"title"];
    cell.detailTextLabel.text = menus[indexPath.section][indexPath.row][@"content"];
    return cell;
}

#pragma mark - UITableView_Delegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSString *title = menus[indexPath.section][indexPath.row][@"title"];
    if ([title isEqualToString:@"性别"]) {
        GBSexPickView *sexPicker = XIB(@"GBSexPickView");
        sexPicker.sexPickResult = ^(NSInteger index, NSString *sexName) {
            
        };
        [sexPicker showAt:self];
        [sexPicker.sexPicker selectRow:1 inComponent:0 animated:NO];
    }else if ([title isEqualToString:@"生日"]) {
        GBDatePickerView *timePicker = XIB(@"GBDatePickerView");
        timePicker.datePicker.datePickerMode = UIDatePickerModeDate;
        [timePicker pickTimeAt:self];
        
    }
    
    else if ([title isEqualToString:@"昵称"]) {
        
        GBTextEditController *textEditor = [[GBTextEditController alloc] initWithNibName:@"GBTextEditController" bundle:nil];
        textEditor.title = @"修改昵称";
        textEditor.textFiled.placeholder = @"请修改昵称";
        [self.navigationController pushViewController:textEditor animated:YES];
        
    }
    
    else if ([title isEqualToString:@"头像"]) {
        
        PortraitPicker *portraitPicker = [[PortraitPicker alloc]init];
        [portraitPicker pickImage:YES atBase:self complete:^(NSMutableArray *selectedPhotos, NSMutableArray *selectedAssets) {
            [SVProgressHUD showWithStatus:@"上传中"];
            [GBOSSUtil uploadImage:selectedPhotos[0] bucket:@"bshop-user" objectKey:@"123546875654/head_koj.jpg" uploadProgress:^(int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
//                [SVProgressHUD showProgress:totalBytesSent/totalBytesExpectedToSend];
            } result:^(OSSTask *task, NSString *url) {
                [SVProgressHUD showInfoWithStatus:@"上传成功"];
            }];
    
        }];
        
    }
    
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 && indexPath.row == 0) {
        return 80;
    }else{
        return 44;
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}




/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
